using System;
using System.Collections.Generic;
using System.Text;

namespace CS6238Project2.Banking.Communication
{
    partial class Transaction : IComparable
    {
        /*
        private string requester;//the name of the person requesting this
        private string authorizer;//the name of the authorizer
        private int account;//the account being affected
        private int value;//the amount it's being changed by
        private DateTime timestamp;
        */

        public override bool Equals(object obj)
        {
            try
            {
                if (!(obj is Transaction))
                {
                    throw new InvalidCastException("Not a valid Transaction object.");
                }
                else
                {
                    Transaction trans1 = (Transaction)obj;
                    return ((trans1.account == this.account) &&
                        (trans1.requester == this.requester) &&
                        (trans1.timestamp == this.timestamp));
                }
            }
            catch (InvalidCastException e)
            {
                Console.WriteLine(e.Message);
            }


            return base.Equals(obj);
        }


        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        /// <summary>
        /// If possible, compares two transactions to each other
        /// </summary>
        /// <param name="obj"></param>
        /// <returns>-1 if it's less, 0 if they're the same, 1 if it's more</returns>
        public int CompareTo(object obj)
        {
            try
            {
                if (!(obj is Transaction))
                {
                    throw new InvalidCastException("Not a valid Transaction object.");
                }
            }
            catch (InvalidCastException e)
            {
                Console.WriteLine(e.Message);
            }

            //cast into an Transaction..
            Transaction transaction = (Transaction)obj;
            //Sort determined by the setting of sortingby...
            switch (Transaction.SortingBy)
            {
                case SortFilter.Value:
                    {
                        return this.adjustment.CompareTo(transaction.adjustment);
                    }
                case SortFilter.Requester:
                    {
                        return this.requester.CompareTo(transaction.requester);
                    }
                case SortFilter.Authorizer:
                    {
                        return this.authorizer.CompareTo(transaction.authorizer);
                    }
                case SortFilter.Account:
                    {
                        return this.account.CompareTo(transaction.account);
                    }
                case SortFilter.Timestamp:
                    {
                        return this.timestamp.CompareTo(transaction.timestamp);
                    }
            }
            return -2;
        }

        /// <summary>
        /// An Enum for different sorting types (number, acctAmount, Last name, first name)
        /// </summary>
        public enum SortFilter
        {
            Value,
            Requester,
            Authorizer,
            Account,
            Timestamp
        }

        /// <summary>
        /// Determines what one is sorting by
        /// </summary>
        private static SortFilter sortingBy = SortFilter.Account;
        public static SortFilter SortingBy
        {
            get { return sortingBy; }
            set { sortingBy = value; }
        }



    }
}
